/******************************************************************************
 * Copyright (C) 2021, Xiaohua Semiconductor Co., Ltd. All rights reserved.
 *
 * This software component is licensed by XHSC under BSD 3-Clause license
 * (the "License"); You may not use this file except in compliance with the
 * License. You may obtain a copy of the License at:
 *                    opensource.org/licenses/BSD-3-Clause
 *
 ******************************************************************************/
 
/******************************************************************************
 ** @file system_hc32l13x.c
 **
 ** @brief Source file for SYSTEM functions
 **
 ** @author MADS Team 
 **
 ******************************************************************************/

/******************************************************************************/
/* Include files                                                              */
/******************************************************************************/
#include "system_hc32l136.h"

#define M0P_SYSCTRL_RCH          (*((volatile uint16_t*)(0x4000200Cul)))

/**
 ******************************************************************************
 ** System Clock Frequency (Core Clock) Variable according CMSIS
 ******************************************************************************/
uint32_t SystemCoreClock;


//add clock source.
void SystemCoreClockUpdate (void) // Update SystemCoreClock variable
{
    SystemCoreClock = 4000000;
}

/**
 ******************************************************************************
 ** \brief  Setup the microcontroller system. Initialize the System and update
 ** the SystemCoreClock variable.
 **
 ** \param  none
 ** \return none
 ******************************************************************************/
void SystemInit(void)
{
    // TODO load trim from flash
    //hcr 4MHz manual trim.
    M0P_SYSCTRL_RCH = (*((volatile uint16_t*) (0x00100C08ul)));    //Loader 4MHz Trimming value                                            

    SystemCoreClockUpdate();

}



